import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:share_fit/app/controllers/sports/sports_logic.dart';
import 'package:share_fit/app/tools/color_const.dart';

class SportsPage extends StatelessWidget {
  SportsPage({super.key});

  final logic = Get.put(SportsLogic());
  final state = Get.find<SportsLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: GetBuilder<SportsLogic>(
          id: 'sport_list',
          builder: (ctrl) => TabBar(
            onTap: (index) => ctrl.selectSport(index),
            controller: ctrl.tabController,
            // 默认是TabAlignment.startOffset, 导致左侧存在很大边距
            tabAlignment: TabAlignment.start,
            // 隐藏底部黑线
            dividerHeight: 0,
            tabs: ctrl.state.sportList.map((item) => Tab(text: item.getTypeName)).toList(),
            isScrollable: true,
            indicatorColor: Colors.red,
            labelColor: ColorConst.activeColor,
          ),
        ),
        // actions: [
        //   GestureDetector(
        //     onTap: () => logic.onAddSportItem(),
        //     child: SizedBox(
        //       width: 100.w,
        //       child: Icon(Icons.add, size: 90.w),
        //     ),
        //   ),
        // ],
      ),
      body: Container(
        decoration: BoxDecoration(borderRadius: BorderRadius.circular(60.r)),
        child: Stack(
          fit: StackFit.expand,
          alignment: Alignment.center,
          children: [
            GoogleMap(
              mapToolbarEnabled: false,
              zoomControlsEnabled: false,
              mapType: MapType.normal,
              initialCameraPosition: const CameraPosition(target: LatLng(0, 0), zoom: 15.0),
              myLocationEnabled: false,
              zoomGesturesEnabled: false,
              tiltGesturesEnabled: false,
              myLocationButtonEnabled: false,
              onMapCreated: (GoogleMapController controller) => logic.onMapCreated(controller),
            ),
            Positioned(
              bottom: 20.h,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  GestureDetector(
                    child: Image.asset('assets/images/sports/icon_sport_target.png'),
                    onTap: () => logic.goGoalSettingPage() /*logic.startExercise()*/,
                  ),
                  GestureDetector(
                    child: Image.asset('assets/images/sports/go.png', width: 320.w, height: 320.w),
                    onTap: () => logic.goCountDownPage(),
                  ),
                  // GestureDetector(
                  //   child: Image.asset('assets/images/sports/icon_sport_setting.png', width: 260.w, height: 260.h),
                  //   onTap: () => Get.toNamed(SportsRoutes.goalSettingPage) /*logic.startExercise()*/,
                  // ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
